home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / NetMouse ƒ / NetMouse Rcv / NetSlut.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-22  |  5.0 KB  |  210 lines  |  [TEXT/KAHL]

  1. // This code was written Thursday June 22, 1992 by Jorg 'jbx' Brown.
  2. // This code is not freeware; this code is public domain.
  3.  
  4. // Written in Think C 5.0.  Anything less would be unthinkable.
  5.  
  6. #undef SystemSevenOrLater
  7. #define SystemSevenOrLater 1
  8.  
  9. #include "Misc.h"
  10. #include <GestaltEqu.h>
  11. #include <PPCToolbox.h>
  12. #include <EPPC.h>
  13. #include <AppleEvents.h>
  14.  
  15. static    PPCOpenPBRec    PPCOpenRec;
  16. static    PPCPortRec        PPCPort, otherPort;
  17. static    LocationNameRec    LNR, otherLoc;
  18.  
  19. static    short    PPC_waiting = 1;
  20. static    short    call_inform = 0;
  21. static    char    buffer[512];
  22. static    short    new_mouse;
  23. PPCInformPBRec    Informant;
  24. short    whichReader = 1;
  25. PPCReadPBRec    Reader1, Reader2;
  26.  
  27. static void pJGNEFilter(void);
  28.  
  29. void main(void) {
  30.     short i;
  31.  
  32.     SetA4(&main);
  33.     asm {
  34.         lea        @pj+2,a0
  35.         move.l    JGNEFilter,(a0)
  36.         bne.s    @nrm
  37.         move.w    #0x4E75,-2(a0)
  38. nrm:    lea        @ptch,a0
  39.         move.l    a0,JGNEFilter
  40.     };
  41.  
  42.     DetachResource(RecoverHandle(&main));
  43.  
  44.     for (i = 1000; i < 1006; i++) {
  45.         ShowINIT(0, i);
  46.         jbxDelay(15);
  47.     }
  48.     ShowINIT(1006, 0);
  49.     
  50.     for (i = 2000; i < 2004; i++) {
  51.         ShowINIT(0, i);
  52.         jbxDelay(15);
  53.     }
  54.     ShowINIT(2004, 0);
  55.     
  56.     return;
  57.     
  58.     if (0) asm {    /* let's not execute the patch code, shall we? */
  59. ptch:    cmpi.w    #nullEvent,OFFSET(EventRecord, what)(a1)
  60.         bne        @pj
  61.         movem.l    a0-a1/a4/d0-d2,-(a7)
  62.         lea        main,a4
  63.         move.l    a1,-(a7)
  64.         jsr        pJGNEFilter
  65.         addq    #4,a7
  66.         movem.l    (a7)+,a0-a1/a4/d0-d2
  67.         cmpi.w    #nullEvent,OFFSET(EventRecord, what)(a1)
  68.         beq.s    @pj
  69.         moveq    #1,d0
  70.         move.w    d0,4(a7)
  71. pj:        jmp        0x12345678
  72.     }
  73. }
  74.  
  75. extern Point Mouse : 0x830;
  76. extern char MBState : 0x172;
  77. extern char CrsrBusy : 0x8CD;
  78. extern char CrsrVis : 0x8CC;
  79. extern char CrsrObscure : 0x8D2;
  80.  
  81. static void InformHappened(void) {
  82.     PPCReadPBRec *px;
  83.     asm {
  84.         movem.l    a0/a1/a4/d0/d1/d2,-(a7)
  85.         lea        main,a4
  86.     }
  87.  
  88.     px = &Reader1;
  89.     if (whichReader == 2) {
  90.         px = &Reader2;
  91.     }
  92.     if (px->ioResult == noErr) {
  93.         if (px->actualLength == 6) {
  94.             struct {
  95.                 Point    ms;
  96.                 short    down;
  97.             } MouseData;
  98.             BlockMove(&buffer, &MouseData, sizeof(MouseData));
  99.  
  100.             if (MouseData.ms.h < CrsrPin.left)   MouseData.ms.h = CrsrPin.left;
  101.             if (MouseData.ms.h > CrsrPin.right)  MouseData.ms.h = CrsrPin.right;
  102.  
  103.             if (MouseData.ms.v < CrsrPin.top)    MouseData.ms.v = CrsrPin.top;
  104.             if (MouseData.ms.v > CrsrPin.bottom) MouseData.ms.v = CrsrPin.bottom;
  105.  
  106.                 // incoming message!
  107.             if (MouseData.ms.v != Mouse.v || MouseData.ms.h != Mouse.h) {
  108.                 if (!CrsrBusy) {
  109.                     short hide = 0;
  110.                     if (CrsrVis && !CrsrObscure) {
  111.                         hide = 1;
  112.                         HideCursor();
  113.                     }
  114.                     *(Point *)0x828 = MouseData.ms;
  115.                     *(Point *)0x82C = MouseData.ms;
  116.                     *(Point *)0x830 = MouseData.ms;
  117.                     if (hide || CrsrObscure) {
  118.                         ShowCursor();
  119.                     }
  120.                 }
  121.             }
  122.         } else if (px->actualLength == sizeof(EventRecord)) {
  123.             EvQElPtr eqp;
  124.             EventRecord er = *(EventRecord *)&buffer;
  125.             if (er.what == mouseDown && MBState < 0) {
  126.                 MBState &= 0x7F;
  127.             } else if (er.what == mouseDown && MBState < 0) {
  128.                 MBState |= 0x80;
  129.             }
  130.             PPostEvent(er.what, er.message, &eqp);
  131.         //    eqp->evtQWhat      = er.what;
  132.         //    eqp->evtQMessage   = er.message;
  133.             eqp->evtQWhere     = er.where;
  134.             eqp->evtQModifiers = er.modifiers;
  135.             if (er.what == mouseDown && MBState < 0) {
  136.                 MBState &= 0x7F;
  137.             } else if (er.what == mouseDown && MBState < 0) {
  138.                 MBState |= 0x80;
  139.             }
  140.         }
  141.         px->actualLength = 20;
  142.     } else if (px->ioResult == sessClosedErr) {
  143.         px->ioResult = noErr;
  144.         Informant.ioCompletion = (void *)&InformHappened;
  145.         Informant.portRefNum = PPCOpenRec.portRefNum;
  146.         Informant.autoAccept = TRUE;
  147.         Informant.portName = &otherPort;
  148.         Informant.locationName = &otherLoc;
  149.         Informant.userName = 0;
  150.         PPC_waiting = PPCInformAsync(&Informant);
  151.         goto inform;
  152.     }
  153.  
  154.     new_mouse = 1;
  155.     whichReader = 3 - whichReader;
  156.  
  157.     px = &Reader1;
  158.     if (whichReader == 2) {
  159.         px = &Reader2;
  160.     }
  161.  
  162.     px->ioCompletion = &InformHappened;
  163.     px->sessRefNum = Informant.sessRefNum;
  164.     px->bufferPtr = buffer;
  165.     px->bufferLength = sizeof(EventRecord);
  166.     px->actualLength = 0;
  167.     PPCReadAsync(px);
  168.  
  169. inform:
  170.     asm {
  171.         movem.l    (a7)+,a0/a1/a4/d0/d1/d2
  172.     }
  173. }
  174.  
  175. static void pJGNEFilter(void) {
  176.     long    PPC_flags;
  177.  
  178.     if (PPC_waiting < 0) return;
  179.     if (PPC_waiting == 1) {
  180.         if (Gestalt(gestaltPPCToolboxAttr, &PPC_flags) != noErr) return;
  181.         if (!(PPC_flags & gestaltPPCSupportsRealTime)) return;
  182.         Reader1.ioResult = 1;
  183.         Reader2.ioResult = 2;
  184.  
  185.         PPCPort.nameScript = 0;    // smRoman;
  186.         PStringMove("\pNetMouse - pick ME!", PPCPort.name);
  187.         PPCPort.portKindSelector = ppcByString;
  188.         PStringMove("\pMac Hax", PPCPort.u.portTypeStr);
  189.         // PPCPort.u.port.creator
  190.         // PPCPort.u.port.type
  191.  
  192.         PPCOpenRec.ioCompletion = 0;
  193.         PPCOpenRec.serviceType = ppcServiceRealTime;
  194.         PPCOpenRec.resFlag = 0;
  195.         PPCOpenRec.portName = &PPCPort;
  196.         PPCOpenRec.locationName = 0;
  197.         PPCOpenRec.networkVisible = true;
  198.         PPC_waiting = PPCOpenSync(&PPCOpenRec);
  199.         if (PPC_waiting != noErr) return;
  200.  
  201.         Informant.ioCompletion = (void *)&InformHappened;
  202.         Informant.portRefNum = PPCOpenRec.portRefNum;
  203.         Informant.autoAccept = TRUE;
  204.         Informant.portName = &otherPort;
  205.         Informant.locationName = &otherLoc;
  206.         Informant.userName = 0;
  207.         PPC_waiting = PPCInformAsync(&Informant);
  208.         return;
  209.     }
  210. }